Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USWDS-Site - Prettier should run on .md files. #3037

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

cathybaptista
Copy link
Contributor

@cathybaptista cathybaptista commented Dec 30, 2024

Summary

We were ignoring running prettier on markdown files. This can cause inconsistencies and errors when writing MD/Frontmatter.

Example: 1c6453d

Related issue

Note comment:

#2868 (comment)

These are links to these files, there weren't any problems running prettier

pages/design-principles/overview.md (before)
pages/design-principles/overview.md (after)

https://github.com/uswds/uswds-site/blob/main/pages/documentation/maturity-model.md (before)
https://github.com/uswds/uswds-site/blob/cb-enable-prettier-on-markdown/pages/documentation/maturity-model.md (after)

Closes #2868

Problem statement

By not running prettier against .md files (in .prettierignore), we are not ensuring these files are subject to coding standards and proper formatting.

Solution

  1. Remove .md from .prettierignore.
  2. Create two new NPM script to check & fix.
  3. Create CI test for linting and formatting.
    Fix issues.

Major changes

Added new script to config.yml:

  • run:
    name: Check formatting
    command: npm run prettier:check

Prettier check in package.json now checks .md files

lint in package.json runs "npx gulp lintJS lintSass && npm run prettier",

run prettier runs both prettier:md && prettier:scss

Do not run prettier on the vendor directory since we don't manage those md files.

Pipeline before running prettier:

image

Pipeline after running prettier:

image

Testing and review

  1. Pull the branch.
  2. Run prettier.
  3. Notice the changes to the markdown files.
  4. Commit the changed files and push.
  5. Make sure the pipeline doesn't fail because of prettier.

@cathybaptista cathybaptista force-pushed the cb-enable-prettier-on-markdown branch from 3a82e12 to 89e0ace Compare January 31, 2025 15:45
@cathybaptista cathybaptista changed the title cb: updating circleci and package.json to allow CI of md files. USWDS-Site - Prettier should run on .md files. Jan 31, 2025
@cathybaptista cathybaptista marked this pull request as ready for review January 31, 2025 19:11
@cathybaptista cathybaptista requested a review from a team as a code owner January 31, 2025 19:11
@cathybaptista cathybaptista force-pushed the cb-enable-prettier-on-markdown branch from e429e0f to 89e0ace Compare January 31, 2025 19:26
Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cathybaptista good work so far. Confirming that this runs formatting checks. Added comments for improvements.

Please don't forget that we'll also need a commit, or a few, that address the formatting errors so the test can pass.

Running the script locally results in 400+ files changed. We should consider fixing section by section, like all components in a commit, about changes, utils, patterns, etc etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Please make sure to insert an empty line at the end of files. You can enable this setting by default in VS Code.

capture -Code-2025-02-04@2x

@@ -69,6 +69,9 @@ jobs:
- run:
name: Build site assets
command: npm run build:all-assets
- run:
name: Check formatting
command: npm run prettier:check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: This check formatting works, but the build job doesn't seem like the most appropriate place because:

  • The build doesn't rely on formatting being correct
  • If there are formatting errors, we won't know until it's deep into the job
  • We don't know what exactly is being checked

You can see in the workflow that it takes over 2 minutes to check for formatting.

Consider separating it and running before build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USWDS-Site - Feature: Enable prettier on Markdown
2 participants